package com.zmc.lostfound.post.controller;

import com.zmc.lostfound.common.utils.Result;
import com.zmc.lostfound.common.valid.AddGroup;
import com.zmc.lostfound.common.valid.UpdateGroup;
import com.zmc.lostfound.post.service.PostService;
import com.zmc.lostfound.post.vo.post.PostCompleteVO;
import com.zmc.lostfound.post.vo.post.PostDetailInfoVO;
import com.zmc.lostfound.post.vo.post.PostSaveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZMC
 * @description 帖子管理接口
 * @email 2869581855@qq.com
 * @date 2023-07-05 15:49:44
 */
@RestController
@RequestMapping("/post")
@Api(value = "帖子管理接口", tags = "帖子管理接口")
public class PostController {

    private final PostService postService;

    public PostController(PostService postService) {
        this.postService = postService;
    }

    @ApiOperation("按帖子id查询帖子详细信息")
    @GetMapping("/query/detailInfoByPostId/{postId}")
    public Result queryDetailInfoByPostId(@PathVariable("postId") Long postId) {
        PostDetailInfoVO postDetailInfoVO = postService.queryDetailInfoByPostId(postId);
        return Result.ok("查询成功").put("postDetailInfoVO", postDetailInfoVO);
    }

    @ApiOperation("用户发布帖子")
    @PostMapping("/publish")
    public Result publish(@RequestBody @Validated(value = {AddGroup.class}) PostSaveVO postSaveVO) {
        return postService.publish(postSaveVO);
    }

    @ApiOperation("用户修改帖子信息")
    @PutMapping("/updatePost")
    public Result updatePost(@RequestBody @Validated(value = {UpdateGroup.class}) PostSaveVO postSaveVO) {
        return postService.updatePost(postSaveVO);
    }

    @ApiOperation("用户完成帖子")
    @PutMapping("/complete")
    public Result complete(@RequestBody @Validated PostCompleteVO postCompleteVO) {
        return postService.complete(postCompleteVO);
    }

    @ApiOperation("按帖子id删除帖子")
    @DeleteMapping("/delete/{postId}")
    public Result deleteByPostId(@PathVariable("postId") Long postId) {
        return postService.deleteByPostId(postId);
    }

}
